home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 2 / The Arsenal Files 2 (Arsenal Computer).ISO / os2 / pgmg20c1.exe / PGMGC1.ZIP / INCLUDE / NET / if.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-01  |  11.4 KB  |  278 lines

  1. #ifndef __IF_32H
  2. #define __IF_32H
  3.  
  4. /*
  5.  * Copyright (c) 1982, 1986 Regents of the University of California.
  6.  * All rights reserved.
  7.  *
  8.  * Redistribution and use in source and binary forms are permitted
  9.  * provided that this notice is preserved and that due credit is given
  10.  * to the University of California at Berkeley. The name of the University
  11.  * may not be used to endorse or promote products derived from this
  12.  * software without specific prior written permission. This software
  13.  * is provided ``as is'' without express or implied warranty.
  14.  *
  15.  *      @(#)if.h        7.2 (Berkeley) 12/30/87
  16.  */
  17.  
  18. /*
  19.  * Structures defining a network interface, providing a packet
  20.  * transport mechanism (ala level 0 of the PUP protocols).
  21.  *
  22.  * Each interface accepts output datagrams of a specified maximum
  23.  * length, and provides higher level routines with input datagrams
  24.  * received from its medium.
  25.  *
  26.  * Output occurs when the routine if_output is called, with three parameters:
  27.  *      (*ifp->if_output)(ifp, m, dst)
  28.  * Here m is the mbuf chain to be sent and dst is the destination address.
  29.  * The output routine encapsulates the supplied datagram if necessary,
  30.  * and then transmits it on its medium.
  31.  *
  32.  * On input, each interface unwraps the data received by it, and either
  33.  * places it on the input queue of a internetwork datagram routine
  34.  * and posts the associated software interrupt, or passes the datagram to a raw
  35.  * packet input routine.
  36.  *
  37.  * Routines exist for locating interfaces by their addresses
  38.  * or for locating a interface on a certain network, as well as more general
  39.  * routing and gateway routines maintaining information used to locate
  40.  * interfaces.  These routines live in the files if.c and route.c
  41.  */
  42.  
  43. /*
  44.  * Structure defining a queue for a network interface.
  45.  *
  46.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  47.  */
  48. #pragma pack(4) /* force on doubleword boundary */
  49. struct mbuf;   /* Pre declaration */
  50. struct ifaddr; /* Pre declaration */
  51. struct ifnet {
  52.         char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
  53.         short   if_unit;                /* sub-unit for lower level driver */
  54.         short   if_mtu;                 /* maximum transmission unit */
  55.         short   if_flags;               /* up/down, broadcast, etc. */
  56.         short   if_timer;               /* time 'til if_watchdog called */
  57.         int     if_metric;              /* routing metric (external only) */
  58.         struct  ifaddr *if_addrlist;    /* linked list of addresses per if */
  59.         struct  ifqueue {
  60.                 struct  mbuf *ifq_head;
  61.                 struct  mbuf *ifq_tail;
  62.                 int     ifq_len;
  63.                 int     ifq_maxlen;
  64.                 int     ifq_drops;
  65.         } if_snd;                       /* output queue */
  66. /* procedure handles */
  67.         int     (*if_init)();           /* init routine */
  68.         int     (*if_output)();         /* output routine */
  69.         int     (*if_ioctl)();          /* ioctl routine */
  70.         int     (*if_reset)();          /* bus reset routine */
  71.         int     (*if_watchdog)();       /* timer routine */
  72. /* generic interface statistics */
  73.         int     if_ipackets;            /* do not take icmp redirect flag */
  74.         int     if_ierrors;             /* input errors on interface */
  75.         int     if_opackets;            /* packets sent on interface */
  76.         int     if_oerrors;             /* output errors on interface */
  77.         int     if_collisions;          /* 802.3 flag */
  78. /* end statistics */
  79.         struct  ifnet *if_next;
  80. #ifdef OS2
  81.         u_char  if_adapternum;          /* adapter number */
  82.         u_int if_adaptype;
  83.         u_int if_broadcast;
  84.         u_long if_speed;
  85.  
  86.         /* [db3l] Interface TCP estimates/controls.  Serves the same */
  87.         /* purpose as the per-route values in BSD-Reno, but I didn't */
  88.         /* have to touch any of the route manipulation code.         */
  89.         u_short if_rtt;                 /* Est interface rtt in ms */
  90.         u_short if_rttvar;              /* Est interface rttvar in ms */
  91.         u_short if_rttmin;              /* Fixed interface rttmin in ms */
  92.         u_short if_sendpipe;            /* Send socket buffer/window size */
  93.         u_short if_recvpipe;            /* Recv socket buffer/window size */
  94.         u_short if_ssthresh;            /* Gateway buffer limit (slow strt) */
  95. #endif
  96. };
  97. #pragma pack()   /* reset to default packing */
  98.  
  99. /* [db3l] Definition for scale to use for RTT values above.  Set to ms */
  100. #define IF_RTTSCALE 1000
  101.  
  102. #pragma pack(4) /* force on doubleword boundary */
  103. struct ifmib {
  104.   int ifNumber;  /* number of network interfaces */
  105.   struct iftable {
  106.     int    ifIndex;        /* index of this interface */
  107.     char   ifDescr[45];    /* description             */
  108.     int    ifType;         /* type of the interface   */
  109.     int    ifMtu;          /* MTU of the interface   */
  110.     char   ifPhysAddr[6];  /* MTU of the interface   */
  111.     int    ifOperStatus;
  112.     u_long ifSpeed;
  113.     u_long ifLastChange;
  114.     u_long ifInOctets;
  115.     u_long ifOutOctets;
  116.     u_long ifOutDiscards;
  117.     u_long ifInDiscards;
  118.     u_long ifInErrors;
  119.     u_long ifOutErrors;
  120.     u_long ifInUnknownProtos;
  121.     u_long ifInUcastPkts;
  122.     u_long ifOutUcastPkts;
  123.     u_long ifInNUcastPkts;
  124.     u_long ifOutNUcastPkts;
  125.   } iftable[20];        /* [db3l] Increased table size to 20 (room for 10 */
  126. };                      /* lan - currently 8 used) and 10 serial.         */
  127. #pragma pack()   /* reset to default packing */
  128.  
  129. #define IFF_UP          0x1             /* interface is up */
  130. #define IFF_BROADCAST   0x2             /* broadcast address valid */
  131. #define IFF_DEBUG       0x4             /* turn on debugging */
  132. #define IFF_LOOPBACK    0x8             /* is a loopback net */
  133. #define IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
  134. #define IFF_NOTRAILERS  0x20            /* avoid use of trailers */
  135. #define IFF_RUNNING     0x40            /* resources allocated */
  136. #define IFF_NOARP       0x80            /* no address resolution protocol */
  137. /* next two not supported now, but reserved: */
  138. #define IFF_PROMISC     0x100           /* receive all packets */
  139. #define IFF_ALLMULTI    0x200           /* receive all multicast packets */
  140. #define IFF_BRIDGE     0x1000           /* support token ring routine field */
  141. #define IFF_SNAP       0x2000           /* support extended SAP header */
  142. #define IFF_ETHER      0x4000           /* Ethernet interface */
  143. #define IFF_LOOPBRD    0x8000           /* Ethernet interface */
  144. /* flags set internally only: */
  145. #define IFF_CANTCHANGE  (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
  146.  
  147. /*
  148.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  149.  * input routines have queues of messages stored on ifqueue structures
  150.  * (defined above).  Entries are added to and deleted from these structures
  151.  * by these macros, which should be called with ipl raised to splimp().
  152.  */
  153. #define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  154. #define IF_DROP(ifq)            ((ifq)->ifq_drops++)
  155. #define IF_ENQUEUE(ifq, m) { \
  156.         (m)->m_act = 0; \
  157.         if ((ifq)->ifq_tail == 0) \
  158.                 (ifq)->ifq_head = m; \
  159.         else \
  160.                 (ifq)->ifq_tail->m_act = m; \
  161.         (ifq)->ifq_tail = m; \
  162.         (ifq)->ifq_len++; \
  163. }
  164. #define IF_PREPEND(ifq, m) { \
  165.         (m)->m_act = (ifq)->ifq_head; \
  166.         if ((ifq)->ifq_tail == 0) \
  167.                 (ifq)->ifq_tail = (m); \
  168.         (ifq)->ifq_head = (m); \
  169.         (ifq)->ifq_len++; \
  170. }
  171. /*
  172.  * Packets destined for level-1 protocol input routines
  173.  * have a pointer to the receiving interface prepended to the data.
  174.  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
  175.  * IF_ADJ should be used otherwise to adjust for its presence.
  176.  */
  177. #define IF_ADJ(m) { \
  178.         (m)->m_off += sizeof(struct ifnet  *); \
  179.         (m)->m_len -= sizeof(struct ifnet  *); \
  180.         if ((m)->m_len == 0) { \
  181.                 struct mbuf  *n; \
  182.                 MFREE((m), n); \
  183.                 (m) = n; \
  184.         } \
  185. }
  186. #define IF_DEQUEUEIF(ifq, m, ifp) { \
  187.         (m) = (ifq)->ifq_head; \
  188.         if (m) { \
  189.                 if (((ifq)->ifq_head = (m)->m_act) == 0) \
  190.                         (ifq)->ifq_tail = 0; \
  191.                 (m)->m_act = 0; \
  192.                 (ifq)->ifq_len--; \
  193.                 (ifp) = *(mtod((m), struct ifnet * *)); \
  194.                 IF_ADJ(m); \
  195.         } \
  196. }
  197. #define IF_DEQUEUE(ifq, m) { \
  198.         (m) = (ifq)->ifq_head; \
  199.         if (m) { \
  200.                 if (((ifq)->ifq_head = (m)->m_act) == 0) \
  201.                         (ifq)->ifq_tail = 0; \
  202.                 (m)->m_act = 0; \
  203.                 (ifq)->ifq_len--; \
  204.         } \
  205. }
  206.  
  207. #define IFQ_MAXLEN      50
  208. #define IFNET_SLOWHZ    1               /* granularity is 1 second */
  209.  
  210. /*
  211.  * The ifaddr structure contains information about one address
  212.  * of an interface.  They are maintained by the different address families,
  213.  * are allocated and attached when an address is set, and are linked
  214.  * together so all addresses for an interface can be located.
  215.  */
  216. struct ifaddr {
  217.         struct  sockaddr ifa_addr;      /* address of interface */
  218.         union {
  219.                 struct  sockaddr ifu_broadaddr;
  220.                 struct  sockaddr ifu_dstaddr;
  221.         } ifa_ifu;
  222. #define ifa_broadaddr   ifa_ifu.ifu_broadaddr   /* broadcast address */
  223. #define ifa_dstaddr     ifa_ifu.ifu_dstaddr     /* other end of p-to-p link */
  224.         struct  ifnet  *ifa_ifp;         /* back-pointer to interface */
  225.         struct  ifaddr  *ifa_next;       /* next address for interface */
  226. };
  227.  
  228. /*
  229.  * Interface request structure used for socket
  230.  * ioctl's.  All interface ioctl's must have parameter
  231.  * definitions which begin with ifr_name.  The
  232.  * remainder may be interface specific.
  233.  */
  234. struct  ifreq {
  235. #define IFNAMSIZ        16
  236.         char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
  237.         union {
  238.                 struct  sockaddr ifru_addr;
  239.                 struct  sockaddr ifru_dstaddr;
  240.                 struct  sockaddr ifru_broadaddr;
  241.                 short   ifru_flags;
  242.                 int     ifru_metric;
  243.                 caddr_t ifru_data;
  244.         } ifr_ifru;
  245. #define ifr_addr        ifr_ifru.ifru_addr      /* address */
  246. #define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
  247. #define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
  248. #define ifr_flags       ifr_ifru.ifru_flags     /* flags */
  249. #define ifr_metric      ifr_ifru.ifru_metric    /* metric */
  250. #define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
  251. };
  252.  
  253. /*
  254.  * Structure used in SIOCGIFCONF request.
  255.  * Used to retrieve interface configuration
  256.  * for machine (useful for programs which
  257.  * must know all networks accessible).
  258.  */
  259. struct  ifconf {
  260.         int     ifc_len;                /* size of associated buffer */
  261.         union {
  262.                 caddr_t ifcu_buf;
  263.                 struct  ifreq  *ifcu_req;
  264.         } ifc_ifcu;
  265. #define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
  266. #define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
  267. };
  268.  
  269. #include <net/if_arp.h>
  270. #ifdef KERNEL
  271. struct  ifqueue near rawintrq;               /* raw packet input queue */
  272. struct  ifnet  * near ifnet;
  273. struct  ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
  274. struct  ifaddr *ifa_ifwithdstaddr();
  275. #endif
  276.  
  277. #endif /* __IF_32H */
  278.